package com.xiaoshuidi.cloud.module.contract.controller.admin.contract;

import com.alibaba.fastjson.JSONObject;
import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.contract.dal.dataobject.contract.OrderLateFeeVo;
import com.xiaoshuidi.cloud.module.contract.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.contract.service.contract.OrderLateFeeService;
import com.xiaoshuidi.cloud.module.system.api.apartment.ApartmentManageApi;
import com.xiaoshuidi.cloud.module.system.enums.apartment.ApartmentManageEnum;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @BelongsProject: lease-module-contract
 * @BelongsPackage: com.xiaoshuidi.cloud.module.contract.controller.admin.contract
 * @Author: James
 * @CreateTime: 2023-11-13  17:03
 * @Description: 滞纳金配置
 * @Version: 1.0
 */
@Slf4j
@Tag(name = "账单配置 - 滞纳金配置")
@RestController
@RequestMapping(ApiConstants.NAME + "/orderLateFee")
@RequiredArgsConstructor
public class OrderLateFeeController {

    @Resource
    private OrderLateFeeService orderLateFeeService;
    @Resource
    private ApartmentManageApi apartmentManageApi;
    /*
     * @description:获取滞纳金配置
     * @author: James
     * @date: 2023/11/14 9:53
     * @param: [apartmentId]
     * @return: com.xiaoshuidi.cloud.framework.common.pojo.CommonResult<com.xiaoshuidi.cloud.module.contract.dal.dataobject.contract.OrderLateFeeVo>
     **/
    @GetMapping("/getOrderLateFee")
    public CommonResult<OrderLateFeeVo> getOrderLateFee(Long apartmentId){
        return CommonResult.success(orderLateFeeService.getOrderLateFee(apartmentId));
    }
    /*
     * @description:修改滞纳金配置
     * @author: James
     * @date: 2023/11/14 9:56
     * @param: [orderLateFeeVo]
     * @return: com.xiaoshuidi.cloud.framework.common.pojo.CommonResult<java.lang.Boolean>
     **/
    @PostMapping("/updateOrderLateFee")
    public CommonResult<Boolean> updateOrderLateFee(OrderLateFeeVo orderLateFeeVo){
        return CommonResult.success(orderLateFeeService.updateById(orderLateFeeVo));
    }
    /*
     * @description:保存滞纳金配置
     * @author: James
     * @date: 2023/11/14 10:00
     * @param: [orderLateFeeVo]
     * @return: com.xiaoshuidi.cloud.framework.common.pojo.CommonResult<java.lang.Boolean>
     **/
    @PostMapping("/insertOrderLateFee")
    public CommonResult<Boolean>insertOrderLateFee(OrderLateFeeVo orderLateFeeVo){
        log.info("保存滞纳金参数："+ JSONObject.toJSONString(orderLateFeeVo));
        apartmentManageApi.updateApartment(orderLateFeeVo.getApartmentId(), ApartmentManageEnum.ORDER_CONFIG.getCode());
        return CommonResult.success(orderLateFeeService.save(orderLateFeeVo));
    }

}
























